<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
FlyUI Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="bdgp-imagewidget.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>bdgp-imagewidget.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		This script defines a widget for fetching and displaying images from www.fly-ted.org.
 <BR/><BR/><B>Version: </B>$Revision:538 $ on $Date: 2008-08-27 09:08:41 +0100 (Wed, 27 Aug 2008) $ by $Author: aliman $
 <BR/><BR/><B>Requires:</B><UL>- YAHOO.util.Connect<BR/>- <a href="../../flyui.html#">flyui</a><BR/>- <a href="../../flyui/bdgp/Service.html#">flyui.bdgp.Service</a><BR/>- <a href="../../flyui/flybase/Gene.html#">TODO license terms</a></UL><B>Author:</B> <a href="http://purl.org/net/aliman">Alistair Miles</a>, Graham Klyne, Jun Zhao
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/bdgp/ImageWidget.html">flyui.bdgp.ImageWidget</a></b></td>
    <td>A widget for displaying in situ images from BDGP.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/bdgp/ImageWidget/Controller.html">flyui.bdgp.ImageWidget.Controller</a></b></td>
    <td>A controller class for the BDGP image widget internal MVC.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/bdgp/ImageWidget/DefaultRenderer.html">flyui.bdgp.ImageWidget.DefaultRenderer</a></b></td>
    <td>A default renderer for the BDGP image widget.</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * <span class="attrib">@fileoverview</span>
 * This script defines a widget for fetching and displaying images from www.fly-ted.org.
 * <span class="attrib">@author</span> &lt;a href="http://purl.org/net/aliman"&gt;Alistair Miles&lt;/a&gt;, Graham Klyne, Jun Zhao
 * <span class="attrib">@version</span> $Revision:538 $ on $Date: 2008-08-27 09:08:41 +0100 (Wed, 27 Aug 2008) $ by $Author: aliman $
 * <span class="attrib">@requires</span> YAHOO.util.Connect
 * <span class="attrib">@requires</span> flyui
 * <span class="attrib">@requires</span> flyui.bdgp.Service
 * <span class="attrib">@requires</span> flyui.flybase.Gene
 * TODO license terms
 */</span>
 
<span class="comment">// create a namespace if not already defined</span>
flyui.namespace(<span class="literal">"flyui.bdgp"</span>);


<span class="comment">/*
 * --------------------------------------------------
 * WIDGET
 * --------------------------------------------------
 */</span>


<span class="comment">/**
 * Create a widget.
 * <span class="attrib">@class</span>
 * A widget for displaying in situ images from BDGP.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {flyui.bdgp.Service} service the service to use to fetch data
 * <span class="attrib">@param</span> {flyui.bdgp.DefaultRenderer} renderer the renderer to use
 */</span>
flyui.bdgp.ImageWidget = <span class="reserved">function</span>( service, renderer ) {
	try {
    	<span class="comment">// do initialisation</span>
    	<span class="reserved">this</span>._init(service, renderer);
    }catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget"</span>, error);
    }

};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> flyui.bdgp.Controller
 */</span>
flyui.bdgp.ImageWidget.<span class="reserved">prototype</span>._controller = null;

	
<span class="comment">/**
 * <span class="attrib">@private</span>
 * Initialise the widget.
 * <span class="attrib">@param</span> {flyui.bdgp.Service} service the service to use to fetch data
 * <span class="attrib">@param</span> {flyui.bdgp.DefaultRenderer} renderer the renderer to use
 */</span>
flyui.bdgp.ImageWidget.<span class="reserved">prototype</span>._init = <span class="reserved">function</span>( service, renderer ) {
	try {
		<span class="comment">// create a model</span>
		var model = new flyui.mvcutils.GenericModel2();
		model.setDefinition(flyui.bdgp.ImageWidget.modelDefinition);
		
		<span class="comment">// instantiate the controller</span>
		<span class="reserved">this</span>._controller = new flyui.bdgp.ImageWidget.Controller(model, service, <span class="reserved">this</span>);
		
		<span class="comment">// connect the renderer to the model</span>
		renderer.connect(model);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.prototype._init"</span>, error);
    }
	
};


<span class="comment">/**
 * Find images by any label of a gene product.
 * <span class="attrib">@param</span> {String} geneLabel any gene product label
 */</span>
flyui.bdgp.ImageWidget.<span class="reserved">prototype</span>.findImagesByAnyGeneLabel = <span class="reserved">function</span>( geneLabel ) {
	try {
		<span class="comment">// pass through to controller</span>
		<span class="reserved">this</span>._controller.findImagesByAnyGeneLabel(geneLabel);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.prototype.findImagesByAnyGeneLabel"</span>, error);
    }
	
};


<span class="comment">/**
 * Find images by the given gene.
 * <span class="attrib">@param</span> {flyui.flybase.Gene} gene
 */</span>
flyui.bdgp.ImageWidget.<span class="reserved">prototype</span>.findImagesByGene = <span class="reserved">function</span>( gene ) {
	try {
		<span class="comment">// pass through to controller</span>
		<span class="reserved">this</span>._controller.findImagesByGene(gene);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.prototype.findImagesByGene"</span>, error);
    }
	
}


<span class="comment">/*
 * --------------------------------------------------
 * CONTROLLER
 * --------------------------------------------------
 */</span>


<span class="comment">/**
 * Create a controller.
 * <span class="attrib">@class</span>
 * A controller class for the BDGP image widget internal MVC.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {flyui.mvcutils.GenericModel2} model the model to store widget state data
 * <span class="attrib">@param</span> {flyui.bdgp.Service} service the service to use to fetch data
 * <span class="attrib">@param</span> {flyui.bdgp.ImageWidget} widget the widget to control
 */</span>

flyui.bdgp.ImageWidget.Controller = <span class="reserved">function</span>( model, service, widget ) {
	
	var that = <span class="reserved">this</span>;
	
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._model = model;
	
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._service = service;
	
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._parent = widget;

    <span class="comment">/**
     * <span class="attrib">@private</span>
     * Success case callback for find images operations.
     * <span class="attrib">@param</span> {Array&lt;flyui.bdgp.Image&gt;} images 
     */</span>
	<span class="reserved">this</span>._findImagesSuccess = <span class="reserved">function</span> (images){
		
		flyui.info(<span class="literal">"request success"</span>);
		
		<span class="comment">// set the results</span>
		that._model.set(<span class="literal">"RESULTS"</span>, images);
		
		<span class="comment">// set the state</span>
		that._model.set(<span class="literal">"STATE"</span>, <span class="literal">"READY"</span>);
		
	};
	
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 * Failure case callback for the find images operations.
	 * <span class="attrib">@param</span> response HTTP response object (YUI)
	 */</span>
	<span class="reserved">this</span>._findImagesFailure = <span class="reserved">function</span> (response) {
		
		flyui.err(<span class="literal">"request failed, status "</span>+response.status+<span class="literal">" "</span>+response.statusText);
		
		<span class="comment">// set an error message</span>
		var msg = <span class="literal">"There was an error retrieving data from BDGP, see the logs for more info. The server may be busy or down, please try again later. If this message persists, please contact the Image Bioinformatics Research Group at bioimage@mail.ontonet.org."</span>;		
		that._model.set(<span class="literal">"ERRORMESSAGE"</span>, msg);

		<span class="comment">// set the state</span>
		that._model.set(<span class="literal">"STATE"</span>, <span class="literal">"SERVERERROR"</span>);
			
	}
	
};


<span class="comment">/**
 * Find images by any gene product label
 * <span class="attrib">@param</span> {String} query any gene product label
 */</span>
flyui.bdgp.ImageWidget.Controller.<span class="reserved">prototype</span>.findImagesByAnyGeneLabel = <span class="reserved">function</span> (query){
	try {
		<span class="comment">// pass through to private implementation</span>
		<span class="reserved">this</span>._findImagesByAnyGeneLabel(query, <span class="reserved">this</span>._findImagesSuccess, <span class="reserved">this</span>._findImagesFailure);
	
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.Controller.prototype.findImagesByAnyGeneLabel"</span>, error);
    }
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Private implementation of find images operation, with callback injection to enable testing.
 * <span class="attrib">@param</span> {String} geneLabel any gene product label
 * <span class="attrib">@param</span> {Function} success success case callback
 * <span class="attrib">@param</span> {Function} failure failure case callback
 */</span>
flyui.bdgp.ImageWidget.Controller.<span class="reserved">prototype</span>._findImagesByAnyGeneLabel = <span class="reserved">function</span>(geneLabel, success, failure) {
	try {
		flyui.info(<span class="literal">"flyui.bdgp.ImageWidget.Controller._findImagesByAnyGeneLabel :: request: "</span>+geneLabel);
		
		<span class="comment">// set the model pending</span>
		<span class="reserved">this</span>._model.set(<span class="literal">"STATE"</span>, <span class="literal">"PENDING"</span>);
		
		<span class="comment">// set the query property</span>
		<span class="reserved">this</span>._model.set(<span class="literal">"QUERY"</span>, geneLabel);
		
		<span class="comment">// kick off the request</span>
		<span class="reserved">this</span>._service.findImagesByAnyGeneLabel(geneLabel, success, failure);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.Controller.prototype._findImagesByAnyGeneLabel"</span>, error);
    }
};


<span class="comment">/**
 * Find images by a given gene.
 * <span class="attrib">@param</span> {flyui.flybase.Gene} gene 
 */</span>
flyui.bdgp.ImageWidget.Controller.<span class="reserved">prototype</span>.findImagesByGene = <span class="reserved">function</span>( gene ) {
	try {
		<span class="comment">// pass through to private implementation</span>
		<span class="reserved">this</span>._findImagesByGene(gene, <span class="reserved">this</span>._findImagesSuccess, <span class="reserved">this</span>._findImagesFailure);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.Controller.prototype.findImagesByGene"</span>, error);
    }
	
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Private implementation of find images operation, with callback injection to enable testing.
 * <span class="attrib">@param</span> {flyui.flybase.Gene} gene 
 * <span class="attrib">@param</span> {Function} success success case callback
 * <span class="attrib">@param</span> {Function} failure failure case callback
 */</span>
flyui.bdgp.ImageWidget.Controller.<span class="reserved">prototype</span>._findImagesByGene = <span class="reserved">function</span>( gene, success, failure ) {
	try {
		flyui.info(<span class="literal">"flyui.flyted.ImageWidget.Controller._findImagesByGene :: request: "</span>+gene.flybaseID);
		
		<span class="comment">// set the model pending</span>
		<span class="reserved">this</span>._model.set(<span class="literal">"STATE"</span>, <span class="literal">"PENDING"</span>);
		
		<span class="comment">// set the query property</span>
		<span class="reserved">this</span>._model.set(<span class="literal">"QUERY"</span>, gene);
		
		<span class="comment">// kick off the request</span>
		<span class="reserved">this</span>._service.findImagesByAnyGeneLabel(gene.flybaseID, success, failure);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.Controller.prototype._findImagesByGene"</span>, error);
    }
	
};


<span class="comment">/*
 * --------------------------------------------------
 * MODEL DEFINITION
 * --------------------------------------------------
 */</span>


<span class="comment">/**
 * Widget MVC model definition.
 */</span>
flyui.bdgp.ImageWidget.modelDefinition = {
	properties : [ <span class="literal">"STATE"</span>, <span class="literal">"RESULTS"</span>, <span class="literal">"QUERY"</span>, <span class="literal">"ERRORMESSAGE"</span> ],
	
	values : {
		<span class="literal">"STATE"</span> : [ <span class="literal">"PENDING"</span>, <span class="literal">"READY"</span>, <span class="literal">"SERVERERROR"</span>, <span class="literal">"UNEXPECTEDERROR"</span> ]
	},
	
	initialize : <span class="reserved">function</span>( data ) {
		data[<span class="literal">"STATE"</span>] = <span class="literal">"READY"</span>;
		data[<span class="literal">"RESULTS"</span>] = null;
		data[<span class="literal">"QUERY"</span>] = null;
		data[<span class="literal">"ERRORMESSAGE"</span>] = null;
	}
}


<span class="comment">/*
 * --------------------------------------------------
 * DEFAULT RENDERER
 * --------------------------------------------------
 */</span>


<span class="comment">/**
 * Create a default renderer for the widget.
 * <span class="attrib">@class</span>
 * A default renderer for the BDGP image widget.
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer = <span class="reserved">function</span>() {};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> Element
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._canvas = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> Element
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._pendingPane = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> Element
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._resultsPane = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> Element
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._resultsSummaryPane = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> Element
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._messagePane = null;


<span class="comment">/**
 * Set the element (canvas) to which this renderer will apply and initialise it.
 * <span class="attrib">@param</span> {Element} canvas
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>.setCanvas = <span class="reserved">function</span>( canvas ) {
	
	<span class="reserved">this</span>._canvas = canvas;
	<span class="reserved">this</span>._initCanvas();
	
}


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Initialise the canvas.
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._initCanvas = <span class="reserved">function</span>() {
 	try {
	    YAHOO.util.Dom.addClass(<span class="reserved">this</span>._canvas, <span class="literal">"bdgpImageWidget"</span>);
	    
	    <span class="comment">// set up the pending pane</span>
	    <span class="reserved">this</span>._pendingPane = document.createElement(<span class="literal">"p"</span>);
	    <span class="reserved">this</span>._pendingPane.innerHTML = <span class="literal">"pending..."</span>;
	    <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._pendingPane);
	    YAHOO.util.Dom.addClass(<span class="reserved">this</span>._pendingPane, <span class="literal">"pendingPane"</span>);
	    flyui.mvcutils.hide(<span class="reserved">this</span>._pendingPane);
	    
	    <span class="comment">// set up the message pane</span>
	    <span class="reserved">this</span>._messagePane = document.createElement(<span class="literal">"p"</span>);
	    <span class="reserved">this</span>._messagePane.innerHTML = <span class="literal">"this should never be displayed"</span>;
	    <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._messagePane);
	    YAHOO.util.Dom.addClass(<span class="reserved">this</span>._messagePane, <span class="literal">"messagePane"</span>);
	    flyui.mvcutils.hide(<span class="reserved">this</span>._messagePane);
	    
	    <span class="comment">// setup results summary pane</span>
	    <span class="reserved">this</span>._resultsSummaryPane = document.createElement(<span class="literal">"p"</span>);
	    <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._resultsSummaryPane);
	    YAHOO.util.Dom.addClass(<span class="reserved">this</span>._resultsSummaryPane, <span class="literal">"resultsSummaryPane"</span>);
	    flyui.mvcutils.hide(<span class="reserved">this</span>._resultsSummaryPane);
	        
	    <span class="comment">// setup results pane</span>
	    <span class="reserved">this</span>._resultsPane = document.createElement(<span class="literal">"div"</span>);
	    <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._resultsPane);
	    YAHOO.util.Dom.addClass(<span class="reserved">this</span>._resultsPane, <span class="literal">"resultsPane"</span>);
	    flyui.mvcutils.hide(<span class="reserved">this</span>._resultsPane);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._initCanvas"</span>, error);
    }    
}


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Main callback function for model changes.
 * <span class="attrib">@param</span> {String} type the model property name
 * <span class="attrib">@param</span> {Array} args the from and to values
 * <span class="attrib">@param</span> {flyui.bdgp.ImageWidget.DefaultRenderer} self a self reference
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._onModelChanged = <span class="reserved">function</span>( type, args, self ) {
	try {
		<span class="comment">// map property names to functions</span>
	    var handlers = {
	        <span class="literal">"STATE"</span>:<span class="literal">"_onStateChanged"</span>,
	        <span class="literal">"QUERY"</span>:<span class="literal">"_onQueryChanged"</span>,
	        <span class="literal">"RESULTS"</span>:<span class="literal">"_onResultsChanged"</span>,
	        <span class="literal">"ERRORMESSAGE"</span>:<span class="literal">"_onErrorMessageChanged"</span>
	    };
	    
	    <span class="comment">// select the correct handler function</span>
	    var handler = handlers[type];
	    
	    <span class="comment">// call the handler</span>
	    self[handler](args[0], args[1]);
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._onModelChanged"</span>, error);
    }
    	
}


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Handle a model state change.
 * <span class="attrib">@param</span> {String} from the old state
 * <span class="attrib">@param</span> {String} to the new state
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._onStateChanged = <span class="reserved">function</span> (from, to) {
	try {
	    <span class="reserved">if</span> ( to == <span class="literal">"PENDING"</span> ) {
	        flyui.mvcutils.show(<span class="reserved">this</span>._pendingPane);
	        flyui.mvcutils.hide(<span class="reserved">this</span>._messagePane);
	        flyui.mvcutils.hide(<span class="reserved">this</span>._resultsSummaryPane);
	        flyui.mvcutils.hide(<span class="reserved">this</span>._resultsPane);
	    } 
	    <span class="reserved">else</span> <span class="reserved">if</span> (to == <span class="literal">"READY"</span>) {
	        flyui.mvcutils.hide(<span class="reserved">this</span>._pendingPane);
	        flyui.mvcutils.hide(<span class="reserved">this</span>._messagePane);
	        flyui.mvcutils.show(<span class="reserved">this</span>._resultsSummaryPane);
	        flyui.mvcutils.show(<span class="reserved">this</span>._resultsPane);     
	    }
	    <span class="reserved">else</span> <span class="reserved">if</span> ( to == <span class="literal">"SERVERERROR"</span> || to == <span class="literal">"UNEXPECTEDERROR"</span> ) {
	        flyui.mvcutils.hide(<span class="reserved">this</span>._pendingPane);
	        flyui.mvcutils.show(<span class="reserved">this</span>._messagePane);
	        flyui.mvcutils.hide(<span class="reserved">this</span>._resultsSummaryPane);
	        flyui.mvcutils.hide(<span class="reserved">this</span>._resultsPane);         
	    } 
	    <span class="reserved">else</span> {
	        <span class="comment">// this should never happen</span>
	        throw {name:<span class="literal">"flyui.bdgp.ImageWidget.UnexpectedStateError"</span>, message:<span class="literal">"Invalid state: "</span>+newState};
	    }
    }catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._onStateChanged"</span>, error);
    }
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Handle an error message change.
 * <span class="attrib">@param</span> {String} from the old message
 * <span class="attrib">@param</span> {String} to the new message
 */</span>    
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._onErrorMessageChanged = <span class="reserved">function</span> (from, to){
	try {
    	<span class="reserved">this</span>._messagePane.innerHTML = to;
    }catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._onErrorMessageChanged"</span>, error);
    }
    
};
    
    
<span class="comment">/**
 * <span class="attrib">@private</span>
 * Handle model results change.
 * <span class="attrib">@param</span> {Array&lt;flyui.bdgp.Image&gt;} from the old results
 * <span class="attrib">@param</span> {Array&lt;flyui.bdgp.Image&gt;} to the new results
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._onResultsChanged = <span class="reserved">function</span>(from, to) {
	try {
	    <span class="comment">// render the results summary</span>
	    var numberOfResults = 0;
	    
	    <span class="reserved">if</span> (to.length &gt; 0){
	    	<span class="reserved">for</span> (var i=0; i &lt; to.length; i++){
	    		numberOfResults += to[i].images.length;
	    	}
	    }
	    
	    <span class="reserved">this</span>._renderResultsSummary(<span class="reserved">this</span>._query, numberOfResults);
	    flyui.info(<span class="literal">"the number of results "</span> + to.length);
	    
	    <span class="reserved">if</span> (to.length &gt; 0) { <span class="comment">// if there are some results to render</span>
	        
	        <span class="comment">// empty the content</span>
	        <span class="reserved">this</span>._resultsPane.innerHTML = <span class="literal">""</span>;
	        
	        <span class="comment">// set the content</span>
	        var resultsNode = <span class="reserved">this</span>._imagesToDivHTML(to);
	        flyui.debug(<span class="literal">"results node content:"</span>+resultsNode.innerHTML);
	        <span class="reserved">this</span>._resultsPane.appendChild(resultsNode);
	        
	    }
	    <span class="reserved">else</span> {
	    	
	    	<span class="comment">// clear out the content</span>
	        <span class="reserved">this</span>._resultsPane.innerHTML = <span class="literal">""</span>;
	        
	    }
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._onResultsChanged"</span>, error);
    }
};


<span class="comment">/**
 * Handle model query changed.
 * <span class="attrib">@param</span> {String} from the old query
 * <span class="attrib">@param</span> {String} to the new query
 */</span>    
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._onQueryChanged = <span class="reserved">function</span> (from, to){
	try {
    	<span class="comment">// don't do anything now, store the query and wait till we have more</span>
    	<span class="reserved">this</span>._query = to;
    }catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._onQueryChanged"</span>, error);
    }

}
   
   
<span class="comment">/**
 * Connect the renderer to a model.
 * <span class="attrib">@param</span> {flyiu.mvcutils.GenericModel2} model
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>.connect = <span class="reserved">function</span>( model ) {
	try {
    	model.subscribeAll(<span class="reserved">this</span>._onModelChanged, <span class="reserved">this</span>);
    
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype.connect"</span>, error);
    }
}    


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Render the results summary pane.
 * <span class="attrib">@param</span> {String or flyui.flybase.Gene} query the user's query
 * <span class="attrib">@param</span> {Number} count the number of results
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._renderResultsSummary = <span class="reserved">function</span>( query, count ) {
	try {
		<span class="comment">// build the inner HTML content</span>
	    var content = <span class="literal">"showing "</span>;
	    content += count;
	    content += <span class="literal">" matching image"</span>;    
	    content += (count == 0 || count &gt; 1) ? <span class="literal">"s "</span> : <span class="literal">" "</span>;
	    content += <span class="literal">"from &lt;a href='http://www.fruitfly.org'&gt;www.fruitfly.org&lt;/a&gt; for "</span>;
	
	    <span class="reserved">if</span> (query instanceof flyui.flybase.Gene) {
	        content += <span class="literal">"gene &lt;strong&gt;"</span>+query.symbols.join(<span class="literal">" / "</span>)+<span class="literal">"&lt;/strong&gt; [&lt;a href='http://www.fruitfly.org/cgi-bin/ex/bquery.pl?qtype=report&amp;find="</span>+query.annotationSymbols[0]+<span class="literal">"&amp;searchfield=CG'&gt;BDGP gene report&lt;/a&gt;]"</span>;
	    } <span class="reserved">else</span> {
	        content +=  <span class="literal">"query '"</span>+query+<span class="literal">"'"</span>;
	    }
	    content += <span class="literal">"..."</span>;
	    <span class="comment">// render the content</span>
	    <span class="reserved">this</span>._resultsSummaryPane.innerHTML = content;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._renderResultsSummary"</span>, error);
    }
    
}

flyui.bdgp.ImageWidget.DefaultRenderer.renderDomElementFromList = <span class="reserved">function</span>(outerTag, innerTag, list) {
	try {
		var outerElem = document.createElement(outerTag);
	
		<span class="comment">// can we defer this to caller?  tbody.appendChild(headerRow);</span>
		
		flyui.debug(<span class="literal">"creating outer "</span>+outerTag);
		<span class="reserved">for</span> (var i=0; i&lt;list.length; i++) {
			var innerElem = document.createElement(innerTag);
			innerElem.innerHTML = list[i];
			outerElem.appendChild(innerElem);
		}	
	
		<span class="reserved">return</span> outerElem;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.renderDomElementFromList"</span>, error);
    }	
}

<span class="comment">/**
 * <span class="attrib">@private</span>
 * Render an array of image objects as HTML content.
 * Override this method to get custom rendering.
 * <span class="attrib">@param</span> {Array&lt;flyui.bdgp.Image&gt;} images the images to render
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._imagesToDivHTML = <span class="reserved">function</span>( stages ) {
    try {
	    <span class="comment">// build the content</span>
	    
	    flyui.debug(<span class="literal">"create the table"</span>);
		
		var table = document.createElement(<span class="literal">"table"</span>);
		var thead = document.createElement(<span class="literal">"thead"</span>);
		var tbody = document.createElement(<span class="literal">"tbody"</span>);
		table.appendChild(thead);
		table.appendChild(tbody);
		
		<span class="comment">// set up header row</span>
		var headers = [<span class="literal">"stage and expressions"</span>, <span class="literal">"images"</span>];
		var headerRow = flyui.bdgp.ImageWidget.DefaultRenderer.renderDomElementFromList(<span class="literal">"tr"</span>, <span class="literal">"th"</span>, headers); 
		thead.appendChild(headerRow);
		
		flyui.debug(<span class="literal">"rendering the header "</span> + headers.innnerHTML);
	   
	    <span class="reserved">for</span> ( var s=0; s&lt;stages.length; s++){
	    	flyui.debug(<span class="literal">"creating result row "</span>+stages[s].stageName);
	   	
	    	var cellContents = <span class="reserved">this</span>._imageToTableCellContents(stages[s]);
			var row = flyui.bdgp.ImageWidget.DefaultRenderer.renderDomElementFromList(<span class="literal">"tr"</span>, <span class="literal">"td"</span>, cellContents);
			tbody.appendChild(row);    	
	    	
	    }
	    <span class="reserved">return</span> table;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._imagesToDivHTML"</span>, error);
    }	
    
};

flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._imageToTableCellContents = <span class="reserved">function</span>( stage ) {
	try {
		var imageSet = stage.images;
		
		var firstColumn = stage.stageName + <span class="reserved">this</span>._expressionTermsToDivHTML(imageSet[0]);
			
		var secondColumn = <span class="literal">""</span>;
		
		<span class="reserved">for</span> ( var i=0; i&lt;imageSet.length; i++ ) {
	    
	    	secondColumn += <span class="reserved">this</span>._imageToDivHTML(imageSet[i]);
		}
		
		<span class="reserved">return</span> [firstColumn, secondColumn];
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._imageToTableCellContents"</span>, error);
    }
}

flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._expressionTermsToDivHTML = <span class="reserved">function</span> ( image ){
	
	try {
		var content = <span class="literal">"&lt;div class=\"</span>terms\<span class="literal">"&gt;"</span>;
		var expressionTerms = image.expressions;
		content += <span class="literal">"&lt;ul&gt;"</span>;
		<span class="reserved">for</span> (var t=0; t&lt;expressionTerms.length; t++){
			content += <span class="literal">"&lt;li&gt;"</span> + expressionTerms[t] + <span class="literal">"&lt;/li&gt;"</span>;
		}
		content += <span class="literal">"&lt;/ul&gt;&lt;/div&gt;"</span>;
		<span class="reserved">return</span> content;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._expressionTermsToDivHTML"</span>, error);
    }
}

<span class="comment">/**
 * <span class="attrib">@private</span>
 * Render an image object as HTML content.
 * Override this method to get custom rendering.
 * <span class="attrib">@param</span> {flyui.bdgp.Image} image the image to render
 */</span>
flyui.bdgp.ImageWidget.DefaultRenderer.<span class="reserved">prototype</span>._imageToDivHTML = <span class="reserved">function</span>( image ) {
    
    try {
	    var content =   <span class="literal">"&lt;div class=\"</span>result\<span class="literal">"&gt;"</span>;
	    content +=          <span class="literal">"&lt;a href=\"</span><span class="literal">" + image.fullImageURL + "</span>\<span class="literal">"&gt;"</span>;
	    content +=              <span class="literal">"&lt;img src=\"</span><span class="literal">" + image.thumbnailURL + "</span>\<span class="literal">" alt=\"</span><span class="reserved">this</span> is an image\<span class="literal">"&gt;"</span>;
	    content +=          <span class="literal">"&lt;/img&gt;&lt;/a&gt;"</span>; 
	    content +=      <span class="literal">"&lt;/div&gt;"</span>;
	    
	    <span class="reserved">return</span> content;
    }catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImageWidget.DefaultRenderer.prototype._imageToDivHTML"</span>, error);
    }
};
 

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Tue Dec  9 11:08:18 2008</div>
</body>
</html>
